﻿/// Copyright © 2013 Microsoft Corporation. 
/// This project is released under the Microsoft Public License (MS-PL)
///
namespace DataMorph.Common.Contracts
{
    using System;

    using Microsoft.WindowsAzure.Storage.Queue;

    public class ProcessingWorkRequest
    {
        private CloudQueueMessage messageReference;

        private IWorkQueue queueReference;

        public string StorageAccountName { get; set; }

        public string DataSetName { get; set; }

        public string File { get; set; }

        public DateTimeOffset TimeRequested { get; set; }

        public void SetMessageReference(CloudQueueMessage cloudMessage)
        {
            this.messageReference = cloudMessage;
        }

        public void SetQueueReference(IWorkQueue workQueue)
        {
            this.queueReference = workQueue;
        }

        public void MarkRequestProcessed()
        {
            if (this.queueReference == null)
            {
                throw new InvalidOperationException("Queue reference cannot be null");
            }

            this.queueReference.DeleteWorkRequest(this);
        }

        public CloudQueueMessage GetMessageReference()
        {
            if (this.messageReference == null)
            {
                throw new InvalidOperationException("Message reference cannot be null");
            }

            return this.messageReference;
        }

        public override string ToString()
        {
            return string.Format("[Storage account:{0}, Data set:{1}, file:{2}]", this.StorageAccountName, this.DataSetName, this.File);
        }
    }
}